<!doctype html>
<html>

	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, maximum-scale = 1, minimum-scale=1" />
		<meta name="apple-mobile-web-app-capable" content="yes" />
		<meta name="viewport" content="target-densitydpi=device-dpi,width=640,user-scalable=0">
		<title>登录</title>
		<link href="css/style.css" rel="stylesheet" type="text/css" />
		<script src="js/mui.min.js"></script>;
		<script src="js/app.js"></script>;
				<script type="text/javascript" language="javascript" src="js/jquery-1.8.2.min.js"></script>
	</head>

	<body>
		<section class="section">
			<div class="top-gray">
				<a href="" class="back"><img src="images/back-gray.png"></a>
				<a class="pro_t">登录</a>
			</div>
			<div class="clear"></div>
			<div class="pos-top">
				<form action="" class="login" method="post">
					<div class="zhmm">
						<label class="user">账号</label>
						<input type="text" class="name01" size="20" maxlength="50" placeholder="请输入账号" name="username" id="username" value="" autocomplete="false" /></div>
					<div class="zhmm">
						<label class="user">密码</label>
						<input type="password" class="pwd" size="20" maxlength="50" placeholder="请输入密码" name="password" id="password" value="" autocomplete="false" /></div>
					<input type="button" class="butl" value="立即登录" id="loginbutton">
					<p >
						<a class="gopage" data-url="reg.html">注册账号</a>
						<a href="" style="margin-right:20px; float:right;">忘记密码</a>
					</p>
				</form>
			</div>
			<script LANGUAGE="JavaScript">
				function CheckAdd() {
					if(login.P_UserName.value == "") {
						alert("请输入账号!");
						login.P_UserName.focus();
						return false;
					}
					if(login.P_Password.value == "") {
						alert("请输入密码!");
						login.P_Password.focus();
						return false;
					}
				}
			</script>
		</section>
	</body>

</html>
<script>
	(function($, doc) {
		$.init({
			statusBarBackground: '#000000'
		});

		$.plusReady(function() {
			var network = true;
			if(mui.os.plus) {
				mui.plusReady(function() {
					if(plus.networkinfo.getCurrentType() == plus.networkinfo.CONNECTION_NONE) {
						network = false;
					}
				});

			}
			mui("body").on("tap", "a", function() {
				if(this.href && this.href != "#") {
					window.location.href = this.href;
				}
			})
			mui("body").on("tap", ".gopage", function() {

				var this_obj = jQuery(this);
				var url = this_obj.data("url");
				var id = this_obj.data("param");
				//  mui.toast(id);
				mui.openWindow({
					id: url,
					url: url,
					extras: {
						data_id: id,

					},
					waiting: {
						autoShow: false,
					}
				})
			});
			var usernameBox = doc.getElementById('username');
			var passwordBox = doc.getElementById('password');

			var loginbutton = doc.getElementById("loginbutton");

			loginbutton.addEventListener('tap', function(event) {
				if(usernameBox.value.length < 5) {
					mui.toast("请输入用户名");
					return;

				}
				if(passwordBox.value.length < 2) {
					mui.toast("请输入密码");
					return;

				}

				var postData = {
					apiUrl: web_url + "/index/customer_login.shtml",
					datas: {
						name: usernameBox.value,
						password: passwordBox.value
					}
				};

				app.postServer(postData,
					function(result) {

						plus.storage.setItem("if_login", "1");
						plus.storage.setItem("name", result.name);
						plus.storage.setItem("password", result.password);
						plus.storage.setItem("user_id", result.uid + "");
						console.log(result.uid);
						console.log(plus.storage.getItem("user_id"));
						var main;
						var web = plus.webview.getWebviewById("main");
						if(web == null) {
							web = plus.webview.create("main.html", "main", "", "");
							web.show();
						} else {
							web.show();
						}

					},
					function(err) {
						if(err) {
							plus.nativeUI.toast(err);
							return;
						}
					}
				);

			}, false);
		});

	}(mui, document));
</script>